package com.ruoyi.service.impl;

import com.ruoyi.domain.SerivrceInfor;
import com.ruoyi.domain.vo.OverviewInfor;
import com.ruoyi.mapper.*;
import com.ruoyi.service.OverviewInforServivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("overviewInforServivce")
public class OverviewInforServivceImpl implements OverviewInforServivce {
    @Autowired
    AbilityUserMapper abilityUserMapper;
    @Autowired
    Ability_BlackListInforMapper ability_BlackListInforMapper;
    @Autowired
    ServiceCreateInforMapper serviceCreateInforMapper;
    @Autowired
    ServceUseingInforMapper servceUseingInforMapper;
    @Autowired
    ServiceSubInforMapper serviceSubInforMapper;
    @Override
    public OverviewInfor getOverviewInfor() {
        OverviewInfor overviewInfor = new OverviewInfor();
        this.setTatol(overviewInfor);
        List<SerivrceInfor> userList= servceUseingInforMapper.getUseingInfor();
        overviewInfor.setUserList(userList.stream().map(SerivrceInfor::getTotal).toArray(Integer[]::new));
        return overviewInfor;
    }

    public void setTatol(OverviewInfor overviewInfor){
        Integer userCount = abilityUserMapper.getTotal().getTotal();
        Integer subCount = serviceSubInforMapper.getTotal().getTotal();
        Integer serviceCount = serviceCreateInforMapper.getTotal().getTotal();
        Integer seruserCount = servceUseingInforMapper.getTotal().getTotal();
        Integer userblockCount = abilityUserMapper.getTotalBlcok().getTotal();
        Integer ipbandCount = ability_BlackListInforMapper.getTotal().getTotal();
        overviewInfor.setUserCount(ReturnTatol(userCount));
        overviewInfor.setSubCount(ReturnTatol(subCount));
        overviewInfor.setServiceCount(ReturnTatol(serviceCount));
        overviewInfor.setSeruserCount(ReturnTatol(seruserCount));
        overviewInfor.setIpbandCount(ReturnTatol(ipbandCount));
        overviewInfor.setUserblockCount(ReturnTatol(userblockCount));
        }

        public String ReturnTatol(Integer a){
        if(a>=100000){
            return "10W+";
        }else if(a>=10000){
            return String.valueOf(a/10000)+"W+";
        }else if(a>=1000){
            return String.valueOf(a/1000)+"K+";
        }else {
            return String.valueOf(a);
        }
        }

    }

